<?php
class aftersales_data_billing {
	public function __construct($app) {
        $this->app = $app;
        $this->mdlApplyRefund = $this->app->model('apply_billing');
    }
    public function saveBilling($aData){
        $ret = $this->mdlApplyRefund->save($aData);
    	if ($ret) {
    		$post = array(
                'method'=>'order.billing',
                'params'=>$aData,
        	);
	        $erp_caller_obj = kernel::service('apioubao.rpc_erp_request');
	        $result = $erp_caller_obj->call_api_oubao($post);
	        $r = json_decode($result,true);
    	}
    }
    public function changeBill($aData){
        // return $aData;
        $rows=$this->mdlApplyRefund->getList('member_id,billing_advance',array('billing_id'=>$aData['billing_id']));
        if($aData['status']=='2'){
            $update=$this->mdlApplyRefund->update(array('status'=>$aData['status'],'billing_advance'=>$rows[0]['billing_advance']-$aData['billing_money'],'memo'=>$aData['memo']),array('billing_id'=>$aData['billing_id']));
            //会员主表改变开票额度by linsuchuan 2018年3月26日14:56:26
            $mdlMember = app::get('b2c')->model('members');
            $mdlMember ->update(array('billing_advance'=>$rows[0]['billing_advance']-$aData['billing_money']),array('member_id'=>$rows[0]['member_id']));
        }elseif($aData['status']=='3'){
             $update=$this->mdlApplyRefund->update(array('status'=>$aData['status'],'memo'=>$aData['memo']),array('billing_id'=>$aData['billing_id']));
        }



    }

}